{template "common/header"}
<ul class="nav nav-tabs">
    <li {if $op == 'list'}class="active"{/if}>
    <a href="{php echo $this->createWebUrl('practice',array('op'=>'list','lid'=>$lid,'sonid'=>$sonid))}" >习题列表</a>
    </li>
    <li {if $op == 'edit'}class="active"{/if}>
    <a href="{php echo $this->createWebUrl('practice',array('op'=>'edit','lid'=>$lid,'sonid'=>$sonid))}" >添加习题</a>
    </li>
    <li {if $op == 'import'}class="active"{/if}>
    <a href="{php echo $this->createWebUrl('practice',array('op'=>'import','lid'=>$lid,'sonid'=>$sonid))}" >导入习题</a>
    </li>
</ul>
{if $op == 'list'}
<div class="row clearfix" >
    <div class="col-md-12 column">
        <div class="list-group">
            <p  class="list-group-item " style="background-color: #D9EDF7" >习题列表：{$lessontitle['title']}->{$sontitle['title']}</p>
            <div active="list-group-item" style="border:1px solid #cecece;">
<!--                <a href="#addcity"  class="btn btn-success" data-toggle="modal"  style="float:right;margin: 15px"><span onclick="clear11()">添加习题</span></a>-->
                <table class="table table-hover table-bordered" style="margin-top:25px;width:98%;text-align:center;table-layout: fixed;" align="center">
                    <thead>
                    <tr>
                        <th style="width: 90px;text-align:center;">
                            {if $paixu == 2}
                            <a href="{php echo $this->createWebUrl('practice',['op'=>'list','paixu'=>1,'lid'=>$lid,'sonid'=>$sonid])}">
                                排序 <img src="{php echo MODULE_URL.'images/up.png'}" alt="" style="height: 14px;">
                            </a>
                            {elseif $paixu == 1}
                            <a href="{php echo $this->createWebUrl('practice',['op'=>'list','paixu'=>2,'lid'=>$lid,'sonid'=>$sonid])}">
                                排序 <img src="{php echo MODULE_URL.'images/down.png'}" alt="" style="height: 14px;">
                            </a>
                            {/if}
                        </th>
                        <th style="width: 90px;text-align:center;">题目类型</th>
                        <th style="width: 90px;text-align:center;">题目问题(仅显示文字)</th>
                        <!--<th style="width: 90px;text-align:center;">题目图片</th>-->
                        <th style="width: 90px;text-align:center;">题目答案</th>
                       <!-- <th style="width: 90px;text-align:center;">题目讲解</th>-->
                        <th style="width: 90px;text-align:center;">状态</th>
                        <th style="width: 90px;text-align:center;">操作</th>
                    </tr>
                    </thead>

                    {loop $practicelist $row}
                    <tr>
                        <td class="paixu" id="{$row['id']}">{$row['sort']}</td>
                        <td>{$row['type']}</td>
                        <td title="{$row['question']}" style="text-align:center;text-align:center;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">{$row['question']}</td>
                        <!--<td><img src="{$_W['attachurl']}{$row['thumb']}" alt="" style="width:80px"></td>-->
                        <td>{$row['answer']}</td>
                       <!-- <td>{$row['analysis']}</td>-->
                        <td>
                            <div class="btn {if $row['status'] == 0}btn-danger{else}btn-info{/if}" data="{$row['id']}"
                                 onclick="changestatus(this)">{if $row['status'] == 0}不显示{else}显示{/if}
                            </div>
                        </td>
                        <td>
                            <a href="{php echo $this->createWebUrl('practice',array('op'=>'edit','id'=>$row['id'],'lid'=>$lid,'sonid'=>$sonid))}" class="btn btn-info">编辑</a>
                            <a href="{php echo $this->createWebUrl('practice',array('op'=>'del','id'=>$row['id'],'lid'=>$lid,'sonid'=>$sonid))}" class="btn btn-danger">删除</a>
                        </td>
                    </tr>
                    {/loop}

                </table>
            </div>
            {$page}
        </div>
    </div>
</div>
<script type="text/javascript">
    function changestatus(obj) {
        var obj = $(obj);
        if (obj.hasClass('btn-danger')) {
            var sta = 1;
        } else {
            var sta = 0;
        }
        var id = obj.attr('data');
        $.ajax({
            type: 'post',
            url: "{php echo $this->createWebUrl('practice',array('op'=>'cstatus'))}",
            data: {sta: sta, id: id},
            success: function (res) {
                var res = JSON.parse(res);
                console.log(res);
                if (res.success == 1) {
                    if (sta == 1) {
                        obj.removeClass('btn-danger');
                        obj.addClass('btn-info');
                        obj.html('显示');
                    } else {
                        obj.removeClass('btn-info');
                        obj.addClass('btn-danger');
                        obj.html('不显示');
                    }
                } else {
                    alert(res.mess);
                }
            }
        });
    }
    $(function(){
        $('.paixu').click(function(){
            if(!$(this).is('.input')){
                $(this).addClass('input').html('<input type="text" id="'+$(this).attr("id") +'" style="width: 50px;" value="'+ $(this).text() +'" />').find('input').focus().blur(function(){
                    var sort=$(this).val();
                    var id=$(this).attr("id");
                    $.ajax({
                        type: 'POST',
                        url: "{php echo $this->createWebUrl('practice',array('op'=>'sort'))}",
                        data: {id:id,sort:sort},
                        success:function(res){
                            var res = JSON.parse(res);
                            location.reload();
                        }
                    });
                    $(this).parent().removeClass('input').html($(this).val() || 0);
                });
            }
        }).hover(function(){
            $(this).addClass('hover');
        },function(){
            $(this).removeClass('hover');
        });
    });
</script>
{/if}

{template "common/footer"}